import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 租户维护
 * @date: 2018-8-10

 */
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
import { parseParameters, filterNullValueObject } from 'utils/utils';
/**
 *获取数据
 * @async
 * @function queryTenant
 * @param {String} params.tenantNum 组织编码
 * @param {String} params.tenantName 组织名称
 * @param {Number} [params.page = 0] - 数据页码
 * @param {Number} [params.size = 10] - 分页大小
 * @returns {Obejct}  fetch Promise
 */

export function queryTenant(_x) {
  return _queryTenant.apply(this, arguments);
}
/**
 *修改组织
 * @async
 * @function updateTenant
 * @returns {Obejct}  fetch Promise
 */

function _queryTenant() {
  _queryTenant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = filterNullValueObject(parseParameters(params));
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenants"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryTenant.apply(this, arguments);
}

export function queryTenantDetail(_x2) {
  return _queryTenantDetail.apply(this, arguments);
}
/**
 *修改组织
 * @async
 * @function updateTenant
 * @param {Number} params.tenantId 组织Id
 * @param {String} params.tenantNum 组织编码
 * @param {String} params.tenantName 组织名称
 * @param {Number} params.enabledFlag 是否启用
 * @param {Number} params.objectVersionNumber 版本号
 * @returns {Obejct}  fetch Promise
 */

function _queryTenantDetail() {
  _queryTenantDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            tenantId = params.tenantId;
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenants/").concat(tenantId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryTenantDetail.apply(this, arguments);
}

export function updateTenant(_x3) {
  return _updateTenant.apply(this, arguments);
}
/**
 *新建组织
 * @async
 * @function addTenant
 * @param {String} params.tenantNum 组织编码
 * @param {String} params.tenantName 组织名称
 * @param {Number} params.enabledFlag 是否启用
 * @param {Number} params.objectVersionNumber 版本号
 * @returns {Obejct}  fetch Promise
 */

function _updateTenant() {
  _updateTenant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            tenantId = params.tenantId;
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenants/").concat(tenantId), {
              method: 'PUT',
              body: params
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateTenant.apply(this, arguments);
}

export function addTenant(_x4) {
  return _addTenant.apply(this, arguments);
}

function _addTenant() {
  _addTenant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenants"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _addTenant.apply(this, arguments);
}